<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 原生的 form 表单自带了按回车提交的功能 -->
    <form id="form">
      <label>用户名：<input type="text" name="aa" /></label>
      <label>密码：<input type="password" name="bb" /></label>
      <button>登录</button>
    </form>

    <script>
      const form = document.querySelector('#form')

      form.addEventListener('submit', (e) => {
        // 阻止表单默认行为
        e.preventDefault()
        console.log('表单校验，校验通过在发送 ajax 请求')
      })
    </script>
  </body>
</html>
